package com.zry.yard.ui.fragment


import android.content.Intent
import android.support.v7.widget.AppCompatTextView
import android.support.v7.widget.LinearLayoutCompat
import android.view.View
import com.zry.yard.MainActivity
import com.zry.yard.R
import com.zry.yard.adapter.HomePageAdapter
import com.zry.yard.animation.RecyclerViewUtilKt
import com.zry.yard.databinding.FragmentHomeBinding
import com.zry.yard.presenter.HomePresenter
import com.zry.yard.ui.activity.*
import com.zry.yard.ui.base.BaseFragment
import com.zry.yard.utils.OneYardUtils
import com.zry.yard.utils.UIUtil

class HomeFragment : BaseFragment() {

    private var mainActivity: MainActivity? = null
    private var homeBinding: FragmentHomeBinding? = null
    private var homePresenter: HomePresenter? = null

    override fun setOnCreate() {
        mainActivity = activity as MainActivity
    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_home
    }

    override fun initDataView() {
        homeBinding = fragmentDataBinding as FragmentHomeBinding
        val commonLeftLinearLayout: LinearLayoutCompat = fragmentDataBinding!!.root.findViewById(R.id.commonLeftLinearLayout)
        commonLeftLinearLayout.visibility = View.GONE
        val titleCenterText: AppCompatTextView = fragmentDataBinding!!.root.findViewById(R.id.titleCenterText)
        titleCenterText.text = getString(R.string.appName)

        homePresenter = HomePresenter(mainActivity!!, homeBinding!!)

        UIUtil.setWidgetHeight(homeBinding!!.homeUserLinear, UIUtil.getScreenWidth(mainActivity) * 300 / 1080)


        homePresenter?.initRecycler()
        homePresenter?.initAdapter()
        homePresenter?.initDataView()
    }


    override fun onResume() {
        super.onResume()
        homePresenter?.initDataView()
    }

    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        homePresenter?.initDataView()
    }
}